<template>
    <div class="Feedback">
        <div class="hp_title">
            <h1>企业合作</h1>
        </div>

        <div class="form">
            <div class="formli">
                <h1>姓名*</h1>
                <h2>
                    <input type="text" v-model="name" />
                </h2>
            </div>
            <div class="formli">
                <h1>单位*</h1>
                <h2>
                    <input type="text" v-model="company" />
                </h2>
            </div>
            <div class="formli">
                <h1>联系方式*</h1>
                <h2>
                    <input type="text" v-model="contact" />
                </h2>
            </div>
            <div class="formli">
                <h1>需求*</h1>
                <h2>
                    <textarea v-model="description"></textarea>
                </h2>
            </div>

            <div class="formbtn" style="margin-top: 30px" @click="subFeedback">
                <span>提交</span>
            </div>
        </div>
    </div>
</template>

<script>
import { axiosPost } from '../../server/axios';
export default {
    name: 'ComPany',
    props: {
        msg: String,
    },
    data() {
        return {
            name: '',
            company: '',
            contact: '',
            description: '',

            time: 60,
        };
    },
    methods: {
        daojishi() {
            let timer = setInterval(() => {
                this.time--;
                if (this.time == 0) {
                    this.time = 60;
                    clearInterval(timer);
                }
            }, 1000);
        },
        subFeedback() {
            if (
                !this.name ||
                !this.company ||
                !this.contact ||
                !this.description
            ) {
                return this.$notify({
                    title: '警告',
                    message: '请填写信息',
                    type: 'warning',
                });
            }
            if (!/^1[3456789]\d{9}$/.test(this.contact)) {
                return this.$notify({
                    title: '警告',
                    message: '请输入正确手机号码',
                    type: 'warning',
                });
            }
            if (this.time != 60) {
                return this.$notify({
                    title: '警告',
                    message: '1分钟内仅可提交一次',
                    type: 'warning',
                });
            }
            axiosPost(
                `/api/cooperation`,
                {
                    type: 'business',
                    name: this.name,
                    company: this.company,
                    contact: this.contact,
                    description: this.description,
                },
                (res) => {
                    console.log(res.data);
                    if (res.code != 'ok') {
                        return this.$notify({
                            title: '警告',
                            message: res.msg,
                            type: 'warning',
                        });
                    }

                    this.name = '';
                    this.company = '';
                    this.contact = '';
                    this.description = '';
                    this.$notify({
                        message: '提交成功',
                        type: 'success',
                    });

                    this.daojishi();
                }
            );
        },
    },
};
</script>
<style scoped lang="scss">
.Feedback {
    padding-bottom: 20px;
}
</style>
